package com.zhang.satokendemo.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhang.satokendemo.config.ApiResult;
import com.zhang.satokendemo.entity.SysUser;
import com.zhang.satokendemo.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Vector;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {
    @Resource
    private ISysUserService sysUserService;

    @PostMapping("/login")
    public ApiResult login(@RequestBody SysUser sysUser){
        SysUser one = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUserId, sysUser.getUserId()));
        if (null != one){
            StpUtil.login(sysUser.getUserId());
            return ApiResult.success(StpUtil.getTokenValue());
        }else {
            return ApiResult.fail("登陆失败");
        }
    }

    public static void main(String[] args) {

    }

}
